/**
 * 全局信息配置类. 不能继承Config类.
 */
import {GlobalConfigBase} from "./GlobalConfigBase";
import {CrossAppInfo} from "../entity/CrossAppInfo";
import {AD_APPS} from "./AD_APPS";

export class GlobalConfig extends GlobalConfigBase {

    // 是否屏蔽分享逻辑.
    public readonly shareEnable: boolean = false;

    // 调试模式.
    public readonly debug: boolean = true;

    public readonly videoAdsId: string = "";
    public readonly bannerAdsId: string = "";
    // 是否允许视频广告.
    public readonly videoEnable: boolean = false;

    // 活动次数限制.
    /**
     *  gongfa : 功法场景. s: share, v:video. b:begin
     *  分享多少次, 视频多少次, 优先哪个.
     */
    public readonly acts = {
        mode: 1,
        "default": {s: 3, v: 1, b: "s"}, // 默认共享这个数据.
    };

    public readonly resBaseUrl: string = "https://cdn.andrewlu.cn";
    // 获取分享文案配置.
    public readonly shareDates = {
        mode: 0,
        baseUrl: null,
        txts: [],
        imgs: [],
    };

    public readonly bannerCfg = {
        mode: 0,
        showing: 0,
        step: 0
    };
    public readonly apps: { [key: number]: CrossAppInfo } = AD_APPS;

    // 获得数组形式的app列表.
    public getCrossApps(): CrossAppInfo[] {
        const app: CrossAppInfo[] = [];
        const adsApp = globalConfig.apps;
        for (let cross in adsApp) {
            if (adsApp.hasOwnProperty(cross)) {
                app.push(adsApp[cross]);
            }
        }
        app.sort((a, b) => {
            return (a.weight - b.weight) || 0;
        });
        return app;
    }
}

export const globalConfig: GlobalConfig = new GlobalConfig();